package com.qzsl.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qzsl.platform.entity.DataSource;
import com.qzsl.platform.mapper.DataSourceMapper;
import com.qzsl.platform.service.IDataSourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tac.base.model.PageQuery;
import com.tac.base.model.SimplePage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xx
 * @since 2023-11-24
 */
@Service
public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSource> implements IDataSourceService {

    /**
     * 分页查询数据源
     *
     * @param pageQuery
     * @return
     */
    @Override
    public SimplePage page(PageQuery pageQuery) {
        int page = pageQuery.getPage();
        int size = pageQuery.getSize();
        Map<String,String> map = pageQuery.convertFilterToMap();
        //数据源类型
        String databaseType = map.get("databaseType");
        LambdaQueryWrapper<DataSource> wr = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(databaseType)) {
            wr.like(DataSource::getDatabaseType,databaseType);
        }
        PageHelper.startPage(page,size);
        List<DataSource> list = list(wr);
        PageInfo<DataSource> dataSourcePageInfo = PageInfo.of(list);

        return SimplePage.of(dataSourcePageInfo);
    }
}
